#pragma once
#include <hash_map>
#include <utility>
#include "Graphic2D.h"
#include "Drawable.h"
#include "Window.h"
using std::string;
using WinApp::Window;
namespace Graphics
{
	enum API_TYPE
	{
		API_UNDEF ,
		API_D3D9 ,
		API_OPENGL
	};

	class GraphicFactory
	{
	private:
		//Static buffer
		static GraphicFactory* m_GF;

		GraphicFactory(const GraphicFactory&);
		GraphicFactory& operator=(const GraphicFactory&);

	protected:
		GraphicFactory();
		stdext::hash_map<string,Drawable*> m_Cache;
		static API_TYPE m_API;

	public:
		virtual ~GraphicFactory(void);

		static void init(std::pair<API_TYPE,Window> param);
		static GraphicFactory* getInstance();

		virtual API_TYPE& GetAPI(void);

		//// Initialize the graphic object by specific API
		//bool Init(API_TYPE api,Window& win);

		// Get the Graphic2D object
		virtual Graphic2D* const GetGraphic2D(void)=0;

		// Create or get a Drawable object from cache
		virtual Drawable* GetDrawableFromCache(const std::string& filename,DWORD colorKey = 0);

		// Create or get a Drawable object from cache
		virtual Drawable* CreateDrawable(int width, int height)=0;
		virtual Drawable* CreateDrawable(const std::string& filename,DWORD colorKey = 0)=0;

	};
}